package it.demosms.service.impl;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import it.demosms.pojo.orm.User;
import it.demosms.service.ifac.TokenService;
import org.springframework.stereotype.Service;

@Service
/**
 * @author 季鑫利
 */
public class TokenServiceImpl implements TokenService {

    @Override
    /**
     * 获取token
     * @param user 用户登录信息
     * @return token
     */
    public String getToken(User user) {

        String token = "";
        //withAudience()保存token信息，把user id和手机号保存
        token = JWT.create().withAudience(Integer.toString(user.getId()))
                .withAudience(user.getPhone())
                .withClaim("userID",user.getId()).
                sign(Algorithm.HMAC256(user.getPassword()));
        return token;
    }

}
